package com.yuanzong.wuliu.config.business;

import com.yuanzong.wuliu.common.utils.UtilsSupport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class RunSupportLoader {

    protected static final Map<String, Object> runSupportBeanMap = new HashMap<>();

    private boolean loaded = false;

    /**
     * 初始化
     */
    public void init() {
        // common - utils
        UtilsSupport utilsSupport = new UtilsSupport();
        runSupportBeanMap.put(utilsSupport.getClass().getName(), utilsSupport);
    }

    /**
     * @param clazz
     * @return
     */
    public <T> T getInstance(Class<T> clazz) {
        if (clazz == null) {
            return null;
        }
        if (!this.loaded) {
            this.init();
        }
        return (T) runSupportBeanMap.get(clazz.getName());
    }

}
